﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using WeChat.Common;

namespace WeChat.ViewModel
{
    class MainWindowModel : NotifyBase
    {
        public CommonBase NavChangeCommand { get; set; }
        //一级窗口
        private FrameworkElement _oneMainContent;

        public FrameworkElement OneMainContent
        {
            get { return _oneMainContent; }
            set { _oneMainContent = value; this.DoNotify(); }
        }
        //二级窗口
        private FrameworkElement _twoMainContent;

        public FrameworkElement TwoMainContent
        {
            get { return _twoMainContent; }
            set { _twoMainContent = value; this.DoNotify(); }
        }


        public MainWindowModel()
        {
            this.NavChangeCommand = new CommonBase();
            this.NavChangeCommand.DoCanExecute = new Func<object, bool>((o) => { return true; });
            this.NavChangeCommand.DoExecute = new Action<Object>(NavChange);
            NavChange("ChatView");
        }

        private void NavChange(object obj)
        {
            string OneContent = obj.ToString();
            Type type = Type.GetType("WeChat.View." + obj.ToString());
            ConstructorInfo cti = type.GetConstructor(Type.EmptyTypes);
            this.OneMainContent = (FrameworkElement)cti.Invoke(null);
            string TwoContent = "";
            if (OneContent == "ChatView")
            {
                TwoContent = "ChatContentView";
            }
            else if (OneContent == "ContactView")
            {
                TwoContent = "ContactContentView";
            }
            else if (OneContent == "CollectView")
            {
                TwoContent = "CollectContentView";
            }
            if (!string.IsNullOrEmpty(TwoContent))
            {
                Type typeTwo = Type.GetType("WeChat.View." + TwoContent.ToString());
                ConstructorInfo ctiTwo = typeTwo.GetConstructor(Type.EmptyTypes);
                this.TwoMainContent = (FrameworkElement)ctiTwo.Invoke(null);
            }
        }
    }
}
